load("@rules_perl//perl:perl_binary.bzl", "perl_binary")
load("@rules_perl//perl:perl_library.bzl", "perl_library")
load("@rules_perl//perl/cpan:cpan_compiler.bzl", "cpan_compiler")

BINARIES = [
    "bin/fix.pl",
    "bin/gendesc",
    "bin/genhtml",
    "bin/geninfo",
    "bin/genpng",
    "bin/lcov",
    "bin/llvm2lcov",
    "bin/perl2lcov",
    "bin/py2lcov",
    "bin/xml2lcov",
]

exports_files(glob(
    include = ["bin/*"],
    exclude = BINARIES,
))

perl_library(
    name = "liblcov",
    srcs = ["lib/lcovutil.pm"],
    includes = ["lib"],
    visibility = ["//visibility:public"],
    deps = [
        "@lcov_deps//:Capture-Tiny",
        "@lcov_deps//:DateTime",
        "@lcov_deps//:Devel-Cover",
        "@lcov_deps//:Memory-Process",
    ],
)

[
    perl_binary(
        name = bin[len("bin/"):],
        srcs = [bin],
        visibility = ["//visibility:public"],
        deps = [":liblcov"],
    )
    for bin in BINARIES
]

# Despite lcov working perfectly fine on macos and windows, it has dependencies
# that are only installable on linux, thus compilation will only succeed there.
cpan_compiler(
    name = "cpan_compiler",
    cpanfile = "cpanfile",
    lockfile = "cpanfile.snapshot.lock.json",
)
